/*
 *  app.cpp
 *  mini
 *
 *  Created by jin on 1/1/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#include "app.h"
#include "factory.h"
#include "appImp.h"

class AppImpBase;

static AppBase* app = 0L;

void miniSetApp(AppBase* theApp)
{
    app = theApp;
}

AppBase* miniGetApp()
{
    return app;
}

int miniEntryWin(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow)
{
    return miniEntryConsole(0, NULL);
}

int miniEntryConsole(int argc, char **argv)
{
    if (app->OnInit())
    {
        app->Run();
    }
    app->OnExit();

    delete app;
    return 0;
}

AppBase::AppBase()
{
    pImp = FACTORY.CreateAppImp(this);
}

AppBase::~AppBase()
{
    delete pImp;
}

bool AppBase::OnInit()
{
    return pImp->OnInit();
}

void AppBase::Run()
{
    pImp->Run();
}

void AppBase::OnExit()
{
}